package apt.dao;

import org.hibernate.Session;
import org.hibernate.Transaction;

import apt.bean.OrderDetailBean;
import apt.common.HibernateUtil;

public class OrderDetailDao {
	private Session session;
	private Transaction transaction;
	
	public boolean addOrderDetail(OrderDetailBean orderDetail) {
		session = HibernateUtil.getSessionFactory().openSession();
		try {
			transaction = session.beginTransaction();
			session.save(orderDetail);
			transaction.commit();
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		} finally {
			session.close();
		}
		return true;
	}

	public boolean updateOrderDetail(OrderDetailBean orderDetail) {
		session = HibernateUtil.getSessionFactory().openSession();
		try {
			transaction = session.beginTransaction();
			session.update(orderDetail);
			transaction.commit();
		} catch (Exception e) {
			transaction.rollback();
		} finally {
			session.close();
		}
		return true;
	}
}
